using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
using System.Xml;

namespace NAst.Common
{
    /// <summary>
    /// Test if the MobilePC is connected to a network
    /// </summary>
    public class IsConnectedTester : INetworkTest
    {
        private bool _expectedValue = false;
        
        #region INetworkTest Members

        /// <summary>
        /// Check if the current network availability
        /// equals the expected availability.
        /// </summary>
        /// <returns></returns>
        public bool Test()
        {
            return System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() == _expectedValue;
        }

        public void Initialize(string stateName, XmlElement config)
        {
            string val = config.GetAttribute("value");
            if (val.Equals("true", StringComparison.InvariantCultureIgnoreCase)
                || val.Equals("true", StringComparison.InvariantCultureIgnoreCase))
            {
                _expectedValue = true;
            }
        }
        #endregion
    }
}
